package com.qf.mybatis;

import com.qf.dao.DeptDao;
import com.qf.dao.PassengerDao;
import com.qf.dao.StudentDao;
import com.qf.pojo.Dept;
import com.qf.pojo.Passenger;
import com.qf.pojo.Student;
import com.qf.utils.MyBatisUtils;
import org.junit.Test;

import java.util.List;

/**
 * @author lixu
 */
public class MybatisResultMap {


    /**
     * 一对一 手动映射
     */
    @Test
    public void testOneToOne(){
        PassengerDao passengerDao = MyBatisUtils.getMapper(PassengerDao.class);

        List<Passenger> passengerList = passengerDao.findOneToOne();

        for (Passenger passenger : passengerList) {
            System.out.println(passenger);
        }

        MyBatisUtils.commit();


    }
    /**
     * 一对多    同学们多对多
     */
    @Test
    public void testOneToMany(){

        DeptDao deptDao = MyBatisUtils.getMapper(DeptDao.class);

        List<Dept> deptList = deptDao.findOneToMany();
        for (Dept dept : deptList) {
            System.out.println(dept);
        }
        MyBatisUtils.commit();

    }
    /**
     * 多对多
     */
    @Test
    public void testManyToMany(){

        StudentDao studentDao = MyBatisUtils.getMapper(StudentDao.class);

        List<Student> studentList = studentDao.findManyToMany();
        for (Student student : studentList) {
            System.out.println(student);
        }
        MyBatisUtils.commit();

    }
}
